<?php


class userAction extends T {


	function __init__() {
		
		/*
			加载模板引擎，设置权限控制
		*/
		
		$this->php->loadview()->loaddb()->session()->helper("function")->init();
		
		if(empty($this->session->userid)) exit("没有权限，这里以后在设置跳转,要注意后台是4个框架。目前想到的方法是现实一个超链接 点击跳出 _top");
	
	
	}


	function index() {
	
		$this->php->view->display("user/index.php");
	
	}
	
	function ht_top(){ $this->php->view->display("user/ht_top.php");}
	function ht_menu(){ $this->php->view->display("user/ht_menu.php");}
	function ht_main(){ $this->php->view->display("user/ht_main.php");}
	function ht_footer(){ $this->php->view->display("user/ht_footer.php");}
	
	/*
		job
	*/
	
	function job_index(){ $this->php->view->display("user/job_index.php");}
	
	function job_jianli_add(){
	
		/*
		$vo = $this->db->settable("job_jianli")->where("userid = ".$this->session->userid)->find();
		if($vo) {
			$this->php->redirect("?a=job_jianli_edit");
			exit();
		}
		*/
		
		$nu = $this->db->settable("job_jianli")->where("userid = ".$this->session->userid)->total();
		if($nu >= 2) {
			echo "目前最多添加2条简历信息，请注意";
			exit();
		}
		
		//$this->php->view->assign("vo",$vo);
	
	
		$this->db->settable("www_tree")->init();
		$list = $this->php->db->select();
		
		
		//行业列表
		$hy_list = list_to_tree($list,"id","pid","_child",2,0);
		$this->view->assign("hy_list",$hy_list);
		
		//地区列表
		$dq_list = list_to_tree($list,"id","pid","_child",6,0);
		$this->view->assign("dq_list",$dq_list);
		
		//工作经验
		$jy_list = list_to_tree($list,"id","pid","_child",7,0);
		$this->view->assign("jy_list",$jy_list);
		
		//薪资要求
		$xz_list = list_to_tree($list,"id","pid","_child",8,0);
		$this->view->assign("xz_list",$xz_list);
		
		//薪资要求
		$xl_list = list_to_tree($list,"id","pid","_child",26,0);
		$this->view->assign("xl_list",$xl_list);
		
		
		$this->php->view->display("user/job_jianli.php");
		
	}
	
	function job_jianli_add_do() {
	
		$this->db->settable("job_jianli")->init();
		
		$_POST["userid"] = $this->session->userid;
		$_POST["ctime"] = time();
		$_POST["etime"] = time();
		
		
		/*
			这里有个漏洞，没检查用户简历数量，用户登录后若知道此接口，可一直添加数据
			懒的改了，希望没这么这么闲的人
		*/
		$vo = $this->db->insert($_POST,0);
		if($vo) {
			echo '修改简历成功';
		}else {
			echo '不好意思，出错了';
		}
		/*
		if($_POST["action_state"] ==0) {
	
			$_POST["userid"] = 15;
			$_POST["ctime"] = time();
			$_POST["etime"] = time();
			
			
			
			$t = $this->php->db->where("userid = 15 ")->find();
			if($t){
			
				echo 'error';
				exit();
			
			}
			
			
			
			
			$vo = $this->php->db->insert($_POST,0);
			
			if($vo) {
				echo '修改简历成功';
			}else {
				echo '不好意思，出错了';
			}
		}else {
		
			
			$_POST["etime"] = time();
			$vo = $this->php->db->where("userid = 15")->update($_POST,0);
			
			if($vo) {
				echo "修改简历成功";
			}else {
				echo "不好意思，出错了";
			}
		
			
		
		}
		*/
		
	
	}
	function job_jianli_list() {
	
		$this->db->settable("job_jianli")->init();
		
		$list = $this->db->where("userid = ".$this->session->userid)->select();
		
		$this->view->assign("list",$list);
		$this->view->display("user/job_jianli_list.php");
	
	}
	
	function job_jianli_edit() {
		$vo = $this->db->settable("job_jianli")->where("id=".$_GET["id"])->find();
		
		if($vo["userid"] != $this->session->userid) exit("edit error");
		
		
		
		
		$this->php->view->assign("vo",$vo);
	
		$this->db->settable("www_tree")->init();
		$list = $this->php->db->select();
		
		
		//行业列表
		$hy_list = list_to_tree($list,"id","pid","_child",2,0);
		$this->view->assign("hy_list",$hy_list);
		
		//地区列表
		$dq_list = list_to_tree($list,"id","pid","_child",6,0);
		$this->view->assign("dq_list",$dq_list);
		
		//工作经验
		$jy_list = list_to_tree($list,"id","pid","_child",7,0);
		$this->view->assign("jy_list",$jy_list);
		
		//薪资要求
		$xz_list = list_to_tree($list,"id","pid","_child",8,0);
		$this->view->assign("xz_list",$xz_list);
		
		//薪资要求
		$xl_list = list_to_tree($list,"id","pid","_child",26,0);
		$this->view->assign("xl_list",$xl_list);
		
		
		$this->php->view->display("user/job_jianli_edit.php");	
	
	}
	
	function job_jianli_update() {
	
		$id = $_POST["id"];
		unset($_POST["id"]);
		
		$vo = $this->db->settable("job_jianli")->where("id=".$id)->find();
		if($vo["userid"] != $this->session->userid) exit("update error");
		
		$_POST["etime"] = time();
		
		$mo = $this->db->where("id=".$id)->update($_POST,0);
		
		if($mo){
			echo "更新简历成功";
		}else{
			echo "更新简历失败";
		}
	
	}
	
	function job_jianli_del() {
		$id = $_GET["id"];
		
		$vo = $this->db->settable("job_jianli")->where("id =".$id)->find();
		if($vo["userid"] != $this->session->userid) exit("del error");
		
		
		if($this->db->where("id = ".$id)->delete() ) {
		
			echo "删除简历条目成功";
		
		}else {
			echo "del error";
		}
		
		
	}
	
	function __destruct () {
	
		
		$debug = C("misc.debug");
		if(empty($debug)) exit();
		
		
		if(!empty($this->php->db)) {
			$str = $this->php->db->getMsg();
			echo "<hr />";
			echo $str;
		}
		
	
	
	}
	
	


}